package common;

import java.util.concurrent.ConcurrentLinkedQueue;

public class Buffer {

	private ConcurrentLinkedQueue<String> list;
	
	public Buffer(){
		list = new ConcurrentLinkedQueue<String>();
	}
	
	public synchronized void offer(String str){
		list.offer(str);
		notifyAll();
	}
	
	public synchronized String poll(){
		while(list.isEmpty()){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return list.poll();
	}
	
	public synchronized String tryPoll(){
		return list.poll();
	}
}
